from rest_framework import serializers

from courses.ser import CourseSerializer
from orders.models import OrderDetail, Order


class OrderDetailSerializer(serializers.ModelSerializer):
    course = CourseSerializer()

    class Meta:
        model = OrderDetail
        fields = "__all__"


class OrderDetailInfoSerializer(serializers.ModelSerializer):
    order_details = OrderDetailSerializer(many=True, read_only=True)
    order_status_text = serializers.CharField(source='get_order_status_display', read_only=True)
    pay_method_text = serializers.CharField(source='get_pay_method_display', read_only=True)

    class Meta:
        model = Order
        fields = ['id', 'order_number', 'total_price',
                  "real_price", "order_status", "order_status_text", "pay_method",
                  "pay_method_text", "order_desc", "order_time",
                  "pay_time", "trade_no", "order_details"]
